<?php
function unicodeDecode($unicode_str){
    $json = '{"str":"'.$unicode_str.'"}';
    $arr = json_decode($json,true);
    if(empty($arr)) return '';
    return $arr['str'];
}
$url = 'https://share.weiyun.com/'.$_GET['wyget'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    curl_close($ch);
    $pattern = '/"html_content":"((?:[^"\\\]++|\\\.)*)"/';
    preg_match($pattern,$html, $matches);
    if (isset($matches[1])) {
    $html_content = $matches[1];
    
$convertedString = unicodeDecode($html_content);
$convertedString2 = strip_tags($convertedString);
$items = explode(',', $convertedString2);
$dataArray = array();
foreach ($items as $item) {
    $parts = explode('|', $item, 2);
    $title = isset($parts[0]) ? trim($parts[0]) : '';
    $content = isset($parts[1]) ? trim($parts[1]) : '';
    $dataArray[] = array(
        'title' => $title,
        'content' => $content
    );
}
$json = json_encode(array(
    'code' => 0,
    'data' => $dataArray
), JSON_UNESCAPED_UNICODE);

echo $json;
    } else {
        echo "未找到 html_content";
    }
}

?>


